/**
 * 
 */
package com.haizhi.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;

import com.haizhi.bean.TbUser;
import com.haizhi.bean.TbUserMessage;
import com.haizhi.dao.UserMessageDao;
import com.haizhi.service.UserMessageService;
import com.haizhi.service.UserService;

/**
 * @author jiangjintai
 *
 */
@Service("userMessage")
public class UserMessageImpl extends BaseServiceImpl<TbUserMessage, Integer> implements UserMessageService {
	@Autowired
	UserMessageDao userMessageDao;
	/* （非 Javadoc）
	 * @see com.haizhi.service.BaseService#findById(java.lang.Object)
	 */
	@Override
	public TbUserMessage findById(Integer id) {
		// 
		return userMessageDao.findOne(id);
	}

	/* （非 Javadoc）
	 * @see com.haizhi.service.BaseService#save(java.lang.Object)
	 */
	@Override
	public TbUserMessage save(TbUserMessage entity) {
		// 
		return userMessageDao.save(entity);
	}

	/* （非 Javadoc）
	 * @see com.haizhi.service.BaseService#delete(java.lang.Object)
	 */
	@Override
	public void delete(TbUserMessage entity) {
		// 
		userMessageDao.delete(entity);
	}

	/* （非 Javadoc）
	 * @see com.haizhi.service.BaseService#findAll()
	 */
	@Override
	public List<TbUserMessage> findAll() {
		// 
		return userMessageDao.findAll();
	}

	/* （非 Javadoc）
	 * @see com.haizhi.service.UserMessageService#findByReceiveUserId(java.lang.Integer, org.springframework.data.domain.Pageable)
	 */
	@Override
	public Page<TbUserMessage> findByReceiveUserId(Integer userId,
			Pageable pageAble) {
		// 
		return userMessageDao.findByTbUserByReceiveUserId_UserId(userId,pageAble);
	}

	/* （非 Javadoc）
	 * @see com.haizhi.service.UserMessageService#saveSendMessage(com.haizhi.bean.TbUser, com.haizhi.bean.TbUser)
	 */
	@Override
	public void saveSendMessage(TbUser tbUser, TbUser targerTbUser,String message) {
		// 
		TbUserMessage tbUserMessage = new TbUserMessage();
		tbUserMessage.setMessageContent(message);
		tbUserMessage.setTbUserByPostUserId(tbUser);
		tbUserMessage.setTbUserByReceiveUserId(targerTbUser);
		tbUserMessage.setMessageTime(new Date());
		this.save(tbUserMessage);
		
	}

	/* （非 Javadoc）
	 * @see com.haizhi.service.impl.BaseServiceImpl#getDao()
	 */
	@Override
	protected JpaRepository<TbUserMessage, Integer> getDao() {
		// 
		return this.userMessageDao;
	}

	
}
